<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="标题" prop="name">
        <el-input v-model="queryParams.name" placeholder="请输入标题" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="问题类型" prop="pbType">
        <el-select v-model="queryParams.pbType" placeholder="请选择问题类型" clearable>
          <el-option v-for="dict in dict.type.arvin_wtlx" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="跟踪人" prop="gzPeople">
        <el-input v-model="queryParams.gzPeople" placeholder="请输入跟踪人" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="优先级" prop="priority">
        <el-select v-model="queryParams.priority" placeholder="请选择优先级" clearable>
          <el-option v-for="dict in dict.type.arvin_yxj" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="业务类型" prop="ywType">
        <el-select v-model="queryParams.ywType" placeholder="请选择业务类型" clearable>
          <el-option v-for="dict in dict.type.arvin_ywlx" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <!-- <el-form-item label="截止时间" prop="endTime">
        <el-date-picker clearable
          v-model="queryParams.endTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择截止时间">
        </el-date-picker>
      </el-form-item> -->
      <!--      <el-form-item label="附件" prop="attachments">
        <el-input
          v-model="queryParams.attachments"
          placeholder="请输入附件"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['arvin:task:add']">新增</el-button>
      </el-col>
      <!--  <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['arvin:task:edit']"
        >修改</el-button>
      </el-col> -->
      <!--  <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['arvin:task:remove']"
        >删除</el-button>
      </el-col> -->
      <!--  <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['arvin:task:export']"
        >导出</el-button>
      </el-col> -->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="taskList" @selection-change="handleSelectionChange" @row-click="handleUpdate">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" prop="id" />
      <el-table-column label="标题" align="center" prop="name" />
      <el-table-column label="指派人" align="center" prop="zpPeople" />

      <el-table-column label="跟踪人" align="center" prop="gzPeople" />
      <!-- <el-table-column label="备注" align="center" prop="remark" /> -->

      <!-- <el-table-column label="问题描述" align="center" prop="problemDescription" /> -->
      <el-table-column label="状态" align="center" prop="state">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.arvin_wtzt" :value="scope.row.state" />
        </template>
      </el-table-column>
      <el-table-column label="优先级" align="center" prop="priority">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.arvin_yxj" :value="scope.row.priority" />
        </template>
      </el-table-column>
      <el-table-column label="问题类型" align="center" prop="pbType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.arvin_wtlx" :value="scope.row.pbType" />
        </template>
      </el-table-column>
      <el-table-column label="业务类型" align="center" prop="ywType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.arvin_ywlx" :value="scope.row.ywType" />
        </template>
      </el-table-column>
      <el-table-column label="截止时间" align="center" prop="endTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.endTime, '{y}-{m}-{d} {h}:{i}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="完成时间" align="center" prop="completionTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.completionTime, '{y}-{m}-{d} {h}:{i}') }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="附件" align="center" prop="attachments" /> -->
      <!--  <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['arvin:task:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['arvin:task:remove']"
          >删除</el-button>
        </template>
      </el-table-column> -->
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改急速任务对话框 -->
    <el-drawer :title="title" :visible.sync="open"  size="string" direction="rtl" width="80%" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="标题" prop="name">
          <el-input v-model="form.name" placeholder="请输入标题" />
        </el-form-item>
        <el-row :gutter="20">
          <el-col :span="8">
            <el-form-item label="指派人" prop="zpPeople">
              <el-select v-model="form.zpPeople" placeholder="选择指派人">
                <el-option v-for="dict in userList" :key="dict.userId" :label="dict.nickName"
                  :value="parseInt(dict.userId)"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="跟踪人" prop="gzPeople">
              <el-select v-model="form.zpPeople" placeholder="选择指派人">
                <el-option v-for="dict in userList" :key="dict.userId" :label="dict.nickName"
                  :value="parseInt(dict.userId)"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="问题类型" prop="pbType">
              <el-select v-model="form.pbType" placeholder="请选择问题类型">
                <el-option v-for="dict in dict.type.arvin_wtlx" :key="dict.value" :label="dict.label"
                  :value="parseInt(dict.value)"></el-option>
              </el-select>
            </el-form-item>
          </el-col>

        </el-row>

        <el-row :gutter="20">
          <el-col :span="8">
            <el-form-item label="业务类型" prop="ywType">
              <el-select v-model="form.ywType" placeholder="请选择业务类型">
                <el-option v-for="dict in dict.type.arvin_ywlx" :key="dict.value" :label="dict.label"
                  :value="parseInt(dict.value)"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="优先级" prop="priority">
              <el-select v-model="form.priority" placeholder="请选择优先级">
                <el-option v-for="dict in dict.type.arvin_yxj" :key="dict.value" :label="dict.label"
                  :value="parseInt(dict.value)"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="所属程碑" prop="milestioneId">
              <el-select v-model="form.priority" placeholder="请选择里程碑">
                <el-option v-for="dict in listMilestones" :key="dict.id" :label="dict.name"
                  :value="parseInt(dict.id)"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>


        <el-form-item label="截止时间" prop="endTime">
          <el-date-picker clearable v-model="form.endTime" type="date" value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="请选择截止时间">
          </el-date-picker>
        </el-form-item>


        <el-form-item label="问题描述">
          <editor v-model="form.problemDescription" :min-height="192" />
        </el-form-item>



        <el-form-item label="附件" prop="attachments">
          <file-upload v-model="form.attachments"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-drawer>
  </div>
</template>

<script>
  import {
    listTask,
    getTask,
    delTask,
    addTask,
    updateTask
  } from "@/api/admin/rapidtest/task";
  import {
    listUser
  } from "@/api/system/user";
  import {
    listMilestone
  } from "@/api/admin/rapidtest/milestone";
  export default {
    name: "Task",
    dicts: ['arvin_wtlx', 'arvin_ywlx', 'arvin_yxj', 'arvin_wtzt'],
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 急速任务表格数据
        taskList: [],
        //所属里程碑
        listMilestones: [],
        //用户列表
        userList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          name: null,
          pbType: null,
          gzPeople: null,
          priority: null,
          problemDescription: null,
          ywType: null,
          endTime: null,
          attachments: null,
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
          name: [{
            required: true,
            message: "标题不能为空",
            trigger: "blur"
          }],
          pbType: [{
            required: true,
            message: "问题类型不能为空",
            trigger: "change"
          }],
          gzPeople: [{
            required: true,
            message: "跟踪人不能为空",
            trigger: "blur"
          }],
          problemDescription: [{
            required: true,
            message: "问题描述不能为空",
            trigger: "blur"
          }],
          ywType: [{
            required: true,
            message: "业务类型不能为空",
            trigger: "change"
          }],
        }
      };
    },
    created() {
      this.getList();
      this.getListUser();
      this.getListMilestone();
    },
    methods: {
      getListUser() {
        listUser().then(response => {

          this.userList = response.rows;
        });
      },
      getListMilestone() {
        listMilestone().then(response => {
           console.log(response.rows)
          this.listMilestones = response.rows;
        });
      },
      /** 查询急速任务列表 */
      getList() {
        this.loading = true;
        listTask(this.queryParams).then(response => {
          this.taskList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          id: null,
          name: null,
          userId: null,
          remarks: null,
          zpPeople: null,
          pbType: null,
          createBy: null,
          gzPeople: null,
          createTime: null,
          updateBy: null,
          updateTime: null,
          remark: null,
          priority: null,
          problemDescription: null,
          ywType: null,
          delFlag: null,
          endTime: null,
          milestioneId: null,
          attachments: null,
          completionTime: null
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = "添加急速任务";
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        const id = row.id || this.ids
        getTask(id).then(response => {
          this.form = response.data;
          this.open = true;
          this.title = "修改急速任务";
        });
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.id != null) {
              updateTask(this.form).then(response => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            } else {
              addTask(this.form).then(response => {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              });
            }
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        this.$modal.confirm('是否确认删除急速任务编号为"' + ids + '"的数据项？').then(function() {
          return delTask(ids);
        }).then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {});
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download('arvin/task/export', {
          ...this.queryParams
        }, `task_${new Date().getTime()}.xlsx`)
      }
    }
  };
</script>
